import { NestFactory } from '@nestjs/core';
import { AppModule } from './app.module';
// 导入swg
import { SwaggerModule, DocumentBuilder } from '@nestjs/swagger';
import { ValidationPipe } from '@nestjs/common';
import { NestExpressApplication } from '@nestjs/platform-express';
// 导入全局异常过滤器
import { AllExceptionFilter } from './core/filters/all-exception.filter';
// 导入全局拦截器
import { HttpReqTransformInterceptor } from './core/interceptors/http-req.interceptor';

async function bootstrap() {
  const app = await NestFactory.create<NestExpressApplication>(AppModule);
  // 全局异常顾虑器
  app.useGlobalFilters(new AllExceptionFilter());
  // 全局拦截器
  app.useGlobalInterceptors(new HttpReqTransformInterceptor());

  // 配置swg
  const options = new DocumentBuilder()
    .setTitle('NestJS API')
    .setDescription('NestJS API description')
    .setVersion('1.0')
    .addTag('NestJS')
    .addBearerAuth({
      type: 'http',
      scheme: 'bearer',
      bearerFormat: 'JWT',
      name: 'JWT',
      description: 'Enter JWT token',
      in: 'header',
    })
    .build();

    const document = SwaggerModule.createDocument(app, options);
    SwaggerModule.setup('api', app, document);

    await app.listen(process.env.PORT ?? 8088);
}
bootstrap();
